package com.yuelao.yuelao_backend.service.impl;

import com.yuelao.yuelao_backend.service.LocationService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LocationServiceImpl implements LocationService {

    @Override
    public Map<String, Object> getLocationData() {
        // 模拟省市区三级联动数据
        // 实际项目中，这些数据可能来自数据库、Redis缓存或外部API
        Map<String, Object> data = new HashMap<>();

        // 广东省
        Map<String, Object> guangdong = new HashMap<>();
        guangdong.put("name", "广东省");
        List<Map<String, Object>> guangdongCities = Arrays.asList(
                createCity("广州市", Arrays.asList("天河区", "越秀区", "海珠区")),
                createCity("深圳市", Arrays.asList("福田区", "罗湖区", "南山区")),
                createCity("珠海市", Arrays.asList("香洲区", "金湾区", "斗门区"))
        );
        guangdong.put("cities", guangdongCities);

        // 湖南省
        Map<String, Object> hunan = new HashMap<>();
        hunan.put("name", "湖南省");
        List<Map<String, Object>> hunanCities = Arrays.asList(
                createCity("长沙市", Arrays.asList("芙蓉区", "天心区", "岳麓区")),
                createCity("株洲市", Arrays.asList("荷塘区", "芦淞区", "石峰区"))
        );
        hunan.put("cities", hunanCities);

        // 湖北省
        Map<String, Object> hubei = new HashMap<>();
        hubei.put("name", "湖北省");
        List<Map<String, Object>> hubeiCities = Arrays.asList(
                createCity("武汉市", Arrays.asList("江岸区", "武昌区", "洪山区")),
                createCity("襄阳市", Arrays.asList("襄城区", "樊城区", "襄州区"))
        );
        hubei.put("cities", hubeiCities);

        data.put("provinces", Arrays.asList(guangdong, hunan, hubei));
        return data;
    }

    private Map<String, Object> createCity(String name, List<String> districts) {
        Map<String, Object> city = new HashMap<>();
        city.put("name", name);
        city.put("districts", districts);
        return city;
    }
}